<?php 
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use cmf\controller\BaseController;
use think\Db;

	class WxpayController extends BaseController
	{

		public function doPay($apply_id){
				/*园区列表*/	
	
		// $where['status'] = 1;
		$url = "v2.crejoy.cn/api/weixin_pay/create_order_min";
	    $data['body'] = $this->request->param('site_name');
	    $data['subject'] = $this->request->param('site_name');
	    $data['amount'] = $this->request->param('amount');
	    $data['token'] = $this->request->param('token');
	    // $data['price'] = $this->request->param('price');
	    // $data['price'] = $this->request->param('price');
	    // $data['staff_id'] = $this->request->param('staff_id');
	    // $data['site_id'] = $this->request->param('site_id');
	    // $data['start_time'] = $this->request->param('start_time');
	    // $data['end_time'] = $this->request->param('end_time');
		//db('cx_orderlist')->insert($data);
		$info = sqcurl($url, 'post', $data, array());
		// var_dump(json_decode($info));
		// exit;
		$order_info = json_decode($info)->data->order_info;
		$order_arr = json_decode($info)->data->order_arr;
		$back['app_id'] = $order_arr->appId;
		$back['nonce_str'] = $order_arr->nonceStr;
		$back['package'] = $order_arr->package;
		$back['sign_type'] = $order_arr->signType;
		$back['timeStamp'] = $order_arr->timeStamp;
		$back['pay_sign'] = $order_arr->paySign;
		$back['order_sn'] = $order_info->order_sn;
		$back['amount'] = $order_info->amount;
		$back['apply_id'] = $apply_id;
		db('orderlist')->insert($back);
		return json($back);
		// object(stdClass)[18]
  // public 'appId' => string 'wx2f4cda8dd0f8f934' (length=18)
  // public 'nonceStr' => string 'kcoHZaJTtvDLcvTn' (length=16)
  // public 'package' => string 'prepay_id=wx201711091854073b928268a50490332503' (length=46)
  // public 'signType' => string 'MD5' (length=3)
  // public 'timeStamp' => string '1510224847' (length=10)
  // public 'paySign' => string '1E4CE5753924EFEDE8A8554BF4A6EBBE' (length=32)




		// object(stdClass)[16]
  // public 'order_sn' => string '2017110950989899' (length=16)
  // public 'amount' => string '1' (length=1)
  // public 'pay_type' => int 2
  // public 'create_time' => string '2017-11-09 18:49:22' (length=19)
  // public 'update_time' => string '2017-11-09 18:49:22' (length=19)
  // public 'status' => int 0

		// $data['order_num'] =$info['order_num'];
		// db('cx_orderlist')->insert($data);
		// if($info){
		// 	return $info;
		// }
		// if ($incubator_type) {
		// 	$where['incubator_type'] = $incubator_type;
		// }

		
		// if(session('incubator_id')){
		// 	$where['incubator_id']=session('incubator_id');
		// }
		// $list=Db::name('incubator')->where($where)->order("sort ASC")->select();


	


		}

		function is_pay(){
			// $data['staff_id'] = $this->request->param('staff_id');
			// $data['site_id'] = $this->request->param('site_id');
			// $data['start_time'] = $this->request->param('start_time');
			// $data['order_num'] = $this->request->param('order_num');
			// $order_num = db('cx_orderlist')->where($data)->value('order_num');
			// $info = sqcurl($url,'post',$condition,array);
			// return $info;
		}






		// function get_order_code(){
		// 	$Ord=M('Orderlist');
		// 	$numbers = range (10,99);
		// 	shuffle ($numbers); 
		// 	$code=array_slice($numbers,0,4); 
		// 	$ordcode=$code[0].$code[1].$code[2].$code[3];
		// 	$oldcode=db('cx_orderlist')->where("ordcode='".$ordcode."'")->getField('ordcode');
		// 	if($oldcode){
		// 		getordcode();
		// 	}else{
		// 		return $ordcode;
		// 	}
		// }
















}